from django.db import models
from users.models import User
from tasks.models import Task
from focus.models import FocusSession  # 如果FocusSession是单独的一个模块的话

class Calendar(models.Model):
    PLAN_TYPE_CHOICES = [
        ('meeting', 'Meeting'),
        ('study', 'Study'),
        ('exercise', 'Exercise'),
        ('work', 'Work'),
        ('other', 'Other')
    ]

    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='calendars')  # 关联用户
    date = models.DateField()  # 计划日期
    start_time = models.TimeField()  # 开始时间
    end_time = models.TimeField()  # 结束时间
    plan_type = models.CharField(max_length=50, choices=PLAN_TYPE_CHOICES)  # 类型
    description = models.TextField(null=True, blank=True)  # 任务描述
    task = models.ForeignKey(Task, on_delete=models.CASCADE, null=True, blank=True, related_name='calendars')  # 关联任务
    session = models.ForeignKey(FocusSession, on_delete=models.CASCADE, null=True, blank=True, related_name='calendars')  # 关联专注会话

    def __str__(self):
        return f"{self.user} - {self.date} {self.start_time} - {self.end_time}"
